package cn.zyf;

import org.apache.commons.text.similarity.LevenshteinDistance;

public class StringSimilarity {

    public static void main(String[] args) {
        new StringSimilarity().run();
    }

    private void run() {
        String s1 = "12345";
        String s2 = "13524";
        System.out.println(getSimilarity(s1, s2));
    }

    private double getSimilarity(String s1, String s2) {
        int distance = getLevenshteinDistance(s1, s2);
        return distance / (double) Math.max(s1.length(), s2.length());
    }

    private int getLevenshteinDistance(String s1, String s2) {
        LevenshteinDistance levenshteinDistance = LevenshteinDistance.getDefaultInstance();
        return levenshteinDistance.apply(s1, s2);
    }

}
